#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setFixedSize(800,600);
    timerID=0;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *e)
{
    qDebug()<<"**********************paintEvent*****************";
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing);    //去掉锯齿
    QPen pen;
    pen.setColor(Qt::red);
    pen.setWidth(5);
    p.setPen(pen);
    p.setBrush(Qt::blue);       //填充
    p.drawLine(0,0,300,300);           // 直线
    p.drawEllipse(400,400,100,100);  //椭圆
    p.drawRect(QRect(200,200,200,200));     //方形
    p.fillRect(100,100,120,120,Qt::gray);

    //////////////////////////////////////////////
//    path.lineTo(100,100);
    path.moveTo(50,50);
    path.cubicTo(200,200,400,400,500,500);
    pahtlineTo(800,600);

    p.drawPaht(path);
}

void MainWindow::timerEvent(QTimerEvent *e)
{
    if(e->timerId()==tiemID)
    {
        percent+=step;
        if(percent<0||perent>1)
        {
            step=-step;
            qBound(0.0,percent,1.0);
        }
    }
}
